﻿using System;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Modules.LINK.Components;
using ASPNETVN.PORTAL.Components.Helpers;
using System.Collections;
using ASPNETVN.PORTAL.Components.Configuration;
using System.Web.UI.WebControls;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.LINK
{
    public enum ModulePages
    {
        Style1,
        Style2,
        Style3,
        Style4,
        StyleCDTM
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            // Define an Array List
            ArrayList list1 = new ArrayList();

            // Sắp xếp theo cột.
            list1.Add(new ListItem("Style1", "Style1"));
            list1.Add(new ListItem("Style2", "Style2"));
            list1.Add(new ListItem("Style3", "Style3"));
            list1.Add(new ListItem("Style4", "Style4"));
            list1.Add(new ListItem("StyleCDTM", "StyleCDTM"));

            ModuleSettingItem settingItem = new ModuleSettingItem(new CustomListDataType(list1, "Text", "Value"));
            settingItem.Value = "StyleCDTM";
            settingItem.Name = "Kiểu hiển thị liên kết";
            settingItem.Description = "Kiểu hiển thị liên kết";
            settingItem.SortOrder = 1;
            this.BaseSettings.Add("DisplayStyle", settingItem);

        }

        private void LoadChildControl()
        {
            const string basePath = "~/Modules/ASPNETVN.PORTAL.Modules.LINK/";
            ModulePages page = (ModulePages)Enum.Parse(typeof(ModulePages), this.Settings["DisplayStyle"].ToString(), true);
            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            ContentPane.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.LoadChildControl();
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "AddEditItem");
        }
    }
}